//
//  EndHolidayViewController.m
//  MobileOffice
//
//  Created by jjkj on 16/11/28.
//  Copyright © 2016年 liaoningjujin. All rights reserved.
//

#import "EndHolidayViewController.h"
#import "ImageDetailViewController.h"
#import "UserHeadImageModel.h"


#define uploadPicInfo @"uploadPicInfo"//上传图片
#define updateEliminateVacationInfo @"updateEliminateVacationInfo"//更新提交销假信息
#define postCommitDealInfo @"postCommitDealInfo"//确认提交信息
#define postDeleteCancelBill @"postDeleteCancelBill"//撤销销假信息

@interface EndHolidayViewController ()<UIImagePickerControllerDelegate,UINavigationControllerDelegate>
{
    NSMutableArray *_photoButtonArr;//签退照片Buton
    NSMutableArray *_photoArr;//所拍照片的arr
    UserHeadImageModel *_imageModel;//头像model
}
@property (nonatomic,strong) UILabel *holidayType;//销假类型
@property (nonatomic,assign) BOOL isEdit;//是否可编辑
@property (nonatomic,strong) UILabel *photoLabel;//
@end

@implementation EndHolidayViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

#pragma mark -初始化数据
- (void)dataInit{
    self.mustSelectArr=[NSMutableArray new];
    self.addWorkPersonArr=[NSMutableArray new];
    _photoButtonArr=[NSMutableArray new];
    _photoArr=[NSMutableArray new];
    _titleArr=@[@"休假开始时间 :",@"休假结束时间 :",@""];
    _messageArr=[NSMutableArray arrayWithArray:@[self.beginStr?self.beginStr:@"点击选择",self.endStr?self.endStr:@"点击选择",@""]];
    if (self.beginStr&&self.endStr) {
        [self getVacateDaysOnlyRequest];
    }
}

//#pragma mark -定时器刷新函数
//- (void)timerFunc
//
//{
//    if (_second>0) {
//        _second--;
//    }else{
//        _minute--;
//        _second=59;
//    }
//    if (_minute<=0) {
//        _timeLabel.textColor=[UIColor redColor];
//    }
//    _timeLabel.text=[NSString stringWithFormat:@"%02ld:%02ld",_minute,_second];
//    //[self setRightNavigation:];
//    if (_minute==0&&_second==0) {
//        [self theTimeOut];
//        [_timer setFireDate:[NSDate distantFuture]];
//    }
//}
//
//#pragma mark -计时器函数
//- (void)theTimeOut{
//    //NSLog(@"时间到了!");
//    DutyParentsViewController *mySelf=self;
//    [LZXHelper postAlertViewControllerWithTitle:@"已超出时间" message:@"请点击'关闭'退出当前页面" cancelButtonTitle:nil otherButtonTitle:@"关闭" cancelEvent:^{
//        
//    } otherEvent:^{
//        if ([_timer isValid]) {
//            [_timer invalidate];
//            _timer=nil;
//        }
//        [mySelf.navigationController popViewControllerAnimated:YES];
//    } viewController:self];
//}

#pragma mark — creatView
- (void)creatView{
    //添加图片
    CGFloat photoButtonWidth=(IPHONE_WIDTH-80*3)/4;//button间隔
    for (int i=0; i<4; i++) {
        UIButton *signButton=[MyControl creatButtonWithFrame:CGRectMake(photoButtonWidth*(i%3+1)+80*(i%3), 32+photoButtonWidth*(i/3)+80*(i/3), 80, 80) target:self sel:@selector(addPhoto:) tag:140+i image:@"AlbumAddBtn@2x" title:nil];
        if (i!=0) {
            signButton.hidden=YES;
        }
        [_photoButtonArr addObject:signButton];
    }
    //创建列表
    _tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, IPHONE_HEIGHT-64) style:UITableViewStyleGrouped];
    //_myTableView.backgroundColor=[UIColor redColor];
    _tableView.delegate=self;
    _tableView.dataSource=self;
    _tableView.tag=110;
    _tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    _tableView.showsVerticalScrollIndicator=NO;
    _tableView.showsHorizontalScrollIndicator=NO;
    _tableView.bounces=NO;
    //[self addTableViewUpdateRefresh:_tableView BindingIdentity:@""];
    //    [self addTableViewLoadMoreData:_tableView BindingIdentity:@""];
    [self.view addSubview:_tableView];
    [self addTableViewFootView];
    
    //    DatePickerView *date=[[DatePickerView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, IPHONE_HEIGHT)];
    //    [[[UIApplication sharedApplication].delegate window] addSubview:date];
}

- (void)addTableViewFootView{
    //添加提交button
    UIView *footView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, 80)];
    footView.backgroundColor=[UIColor clearColor];
    
    NSArray *title=@[@"确定"];
    CGFloat buttonWidth=(IPHONE_WIDTH-(title.count+1)*10)/title.count;
    for (int i=0; i<title.count; i++) {
        UIButton *submitButton=[MyControl creatButtonWithFrame:CGRectMake(10*(i+1)+buttonWidth*i,20, buttonWidth, 40) target:self sel:@selector(submitClick:) tag:120+i image:nil title:title[i]];
        submitButton.layer.masksToBounds=YES;
        submitButton.layer.cornerRadius=5;
        [submitButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        if (i==0) {
            submitButton.backgroundColor=COLOR_MIDBLUE;
        }else{
            submitButton.backgroundColor=[UIColor orangeColor];
        }
        [footView addSubview:submitButton];
    }
    _tableView.tableFooterView=footView;
}

#pragma mark-将textView的提示文字清空
- (void)textViewDidBeginEditing:(UITextView *)textView{
    [self addTapGestureRecognizer];
    if ([textView.text isEqualToString:@"休假时间已到,特申请销假,请批准！"]) {
        textView.textColor=[UIColor blackColor];
        textView.text=@"";
        //将标记取消
        [self setLabelBorderColorWithLabel:self.reasonTitleLabel color:[UIColor clearColor]];
    }
    NSIndexPath* path = [NSIndexPath indexPathForRow:0 inSection:2];
    [self performSelector:@selector(scrollToCell:) withObject:path afterDelay:0];
}

#pragma mark-将textView默认文字设置为提示文字
- (BOOL)textViewShouldEndEditing:(UITextView *)textView{
    [self removeTapGestureRecognizer];
    if (textView.text.length==0) {
        textView.textColor=[UIColor lightGrayColor];
        textView.text=@"休假时间已到,特申请销假,请批准！";
    }
    return YES;
}

//#pragma mark -避免键盘遮挡
//- (void)textViewDidBeginEditing:(UITextView *)textView{
//    [self setLabelBorderColorWithLabel:self.reasonTitleLabel color:[UIColor clearColor]];
//    NSIndexPath* path = [NSIndexPath indexPathForRow:textView.tag-200 inSection:0];
//    [self performSelector:@selector(scrollToCell:) withObject:path afterDelay:0];
//}

-(void) scrollToCell:(NSIndexPath*) path {
    [_tableView scrollToRowAtIndexPath:path atScrollPosition:UITableViewScrollPositionTop animated:YES];
}


#pragma mark - TableViewDelagate

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section==1) {
        return 3;
    }else if (section==2){
        return 1;
    }
    return 1;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section==0) {
        //销假类型
        NSString *cellID=@"DutyBasicTableViewCell";
        DutyBasicTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellID];
        if (!cell) {
            cell=[[DutyBasicTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
        }
        cell.myTitleLabel.text=@"销假类别 :";
        self.holidayType=cell.messageLabel;
        return cell;
    }else if(indexPath.section==1){
        NSString *cellID=@"DutyBasicTableViewCell1";
        DutyBasicTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellID];
        if (!cell) {
            cell=[[DutyBasicTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
            if (indexPath.row<2) {
                //重新设置cell
                cell.myTitleLabel.width+=30;
                cell.messageLabel.x+=30;
                cell.messageLabel.width-=30;
            }else{
                cell.lineLabel.hidden=YES;
                //修改一个标题的布局
                self.photoLabel=cell.myTitleLabel;
                self.photoLabel.textColor=[UIColor redColor];
                self.photoLabel.textAlignment=NSTextAlignmentLeft;
                self.photoLabel.frame=CGRectMake(13, 0, IPHONE_WIDTH-2*13, self.photoLabel.height);
            }
        }
        if(indexPath.row==2){
            //将拍的图片显示出来
            for (int i=0;i<_photoButtonArr.count;i++) {
                UIButton *photo=_photoButtonArr[i];
                if (i<_photoArr.count) {
                    UIImage *image=_photoArr[i];
                    [photo setImage:image forState:UIControlStateNormal];
                    photo.hidden=NO;
                }else{
                    photo.hidden=YES;
                }
                if (i==_photoArr.count) {
                    //[photo setImage:[UIImage imageNamed:@"AlbumAddBtn@2x"] forState:UIControlStateNormal];
                    photo.hidden=NO;
                }
                [cell.contentView addSubview:photo];
            }
        }
        
        //保存疑问按钮
        if (indexPath.row==0) {
            self.beginTitleLabel=cell.myTitleLabel;
        }else if (indexPath.row==1){
            self.endTitleLabel=cell.myTitleLabel;
        }
        if (indexPath.row<2) {
            cell.myTitleLabel.text=_titleArr[indexPath.row];
            cell.messageLabel.text=_messageArr[indexPath.row];
        }
        return cell;
        
    }else{
        NSString *cellID=@"ReasonTextTableViewCell";
        ReasonTextTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellID];
        if (!cell) {
            cell=[[ReasonTextTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID title:nil noticeStr:@"休假时间已到,特申请销假,请批准！"];
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
        }
        self.reasonTextView=cell.reasonTextView;
        self.reasonTextView.delegate=self;
        self.reasonTitleLabel=cell.myTitleLabel;
        return cell;
    }
    //    [cell.headImageView setImage:[UIImage imageNamed:_imageArr[indexPath.section][indexPath.row]]];
    //    cell.myTitle.text=_titleArr[indexPath.section][indexPath.row];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [self.reasonTextView resignFirstResponder];
    if (indexPath.section==1) {
        if (indexPath.row==0||indexPath.row==1) {
            if (!self.isEdit) {
                [LZXHelper postMessageWithText:@"只有提前销假才能修改日期！" View:self.view];
                return;
            }
        }
    }
    if (indexPath.section==1) {
        //选择开始和结束时间执行这里
        if (indexPath.row==0||indexPath.row==1){
            NSString *dateStr=nil;
            if (indexPath.row==0) {
                if (self.beginStr) {
                    dateStr=self.beginStr;
                }
            }
            if (indexPath.row==1) {
                if (self.endStr) {
                    dateStr=self.endStr;
                }
            }
            DatePickerView *datePickerView=[[DatePickerView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, IPHONE_HEIGHT)nowDateStr:dateStr];
            __weak NSMutableArray *myMessageArr=_messageArr;
            __weak UITableView *myTableView=_tableView;
            __weak DutyParentsViewController *mySelf=self;
            datePickerView.sureBlock=^(NSString *timeStr){
                if (indexPath.row==0) {
                    //如果是选择开始时间
                    //先判断有没有结束时间,如果有要进行比对
                    if (mySelf.endStr) {
                        if (![mySelf compareOneTime:timeStr withAnotherTime:mySelf.endStr]) {
                            [LZXHelper postMessageWithText:@"请假结束时间应该在请假开始时间之后!" View:mySelf.view];
                        }
                        [mySelf getVacateDaysOnlyRequest];
                    }
                    if (mySelf.dutyType==ApplyHoliday) {
                        //如果是请假
                        if ([mySelf compareTime:timeStr]) {
                            //比现在的时间早
//                            [LZXHelper postAlertViewControllerWithTitle:@"您选择的请假开始时间早于今天,要补假吗?" message:nil cancelButtonTitle:@"选错时间了" otherButtonTitle:@"去补假" cancelEvent:^{
//                                
//                            } otherEvent:^{
//                                mySelf.dutyType=1;
//                                
//                                [mySelf setNavigationTitle:[mySelf.navaTitle stringByAppendingString:@"补假申请"]];
//                                
//                            } viewController:mySelf];
                        }else{
                            //比现在的时间晚
                            mySelf.beginStr=[timeStr copy];
                            [mySelf setLabelBorderColorWithLabel:mySelf.beginTitleLabel color:[UIColor clearColor]];
                            [myMessageArr replaceObjectAtIndex:indexPath.row withObject:timeStr];
                            [myTableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
                            [mySelf getTimeControlRequestWithBeginTime:[timeStr copy]endTime:nil type:@"Begin"];
                        }
                        
                    }else{
                        //如果是补假
                        if ([mySelf compareTime:timeStr]){
                            //比现在的时间早
                            mySelf.beginStr=[timeStr copy];
                            [mySelf setLabelBorderColorWithLabel:mySelf.beginTitleLabel color:[UIColor clearColor]];
                            [myMessageArr replaceObjectAtIndex:indexPath.row withObject:timeStr];
                            [myTableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
                            [mySelf getTimeControlRequestWithBeginTime:[timeStr copy]endTime:nil type:@"Begin"];
                        }else{
//                            //比现在的时间晚
//                            [LZXHelper postAlertViewControllerWithTitle:@"您选择的请假开始时间晚于今天,要请假吗?" message:nil cancelButtonTitle:@"选错时间了" otherButtonTitle:@"去请假" cancelEvent:^{
//                                
//                            } otherEvent:^{
//                                mySelf.dutyType=0;
//                                [mySelf setNavigationTitle:[mySelf.navaTitle stringByAppendingString:@"申请"]];
//                            } viewController:mySelf];
                        }
                    }
                    
                }else{
                    //点击结束时间
                    mySelf.endStr=[timeStr copy];
                    [mySelf setLabelBorderColorWithLabel:mySelf.endTitleLabel color:[UIColor clearColor]];
                    [myMessageArr replaceObjectAtIndex:indexPath.row withObject:timeStr];
                    [myTableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
                    [mySelf getVacateDaysOnlyRequest];
                    [mySelf getTimeControlRequestWithBeginTime:mySelf.beginStr endTime:[timeStr copy] type:@"End"];
                }
            };
            [[[UIApplication sharedApplication].delegate window] addSubview:datePickerView];
        }
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    //如果是添加工作委托
    if (indexPath.section==2) {
        return 100;
    }else if (indexPath.section==1){
        if (indexPath.row==2) {
            CGFloat photoButtonWidth=(IPHONE_WIDTH-80*3)/4;//button间隔
            //因为还有个增加图片的按钮 所以我加1
            if (_photoArr.count+1>3) {
                NSInteger num=0;
                if ((_photoArr.count+1)%3>0) {
                    num=(_photoArr.count+1)/3+1;
                }else{
                    num=(_photoArr.count+1)/3;
                }
                return 28+photoButtonWidth*num+80*num;
                //        _submitButton.y=_tableView.tableFooterView.height-50;
                //       _tableView.tableFooterView=_footView;
            }else{
                return 136;
            }
        }else{
            return 50;
        }
    }
    return 50;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    //行程计划
    if (section==2) {
        UIView *backView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, 50)];
        
        
        UILabel *myTitleLabel=[MyControl creatLabelWithFrame:CGRectMake(8, 10, 80, 30) text:@""];
        myTitleLabel.textAlignment=NSTextAlignmentCenter;
        myTitleLabel.layer.masksToBounds=YES;
        myTitleLabel.layer.cornerRadius=5;
        myTitleLabel.text=@"销假说明 :";
        [backView addSubview:myTitleLabel];
        return backView;
    }
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section==2) {
        return 50;
    }

    return 20;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 1;
}

#pragma mark -提交按钮
- (void)submitClick:(UIButton *)button{
    
    if (_photoArr.count==0) {
        [LZXHelper postMessageWithText:@"请上传销假证明!" View:self.view];
        return;
    }
    [self uploadPhotoImage];
}

#pragma mark - 拍照按钮点击

- (void)addPhoto:(UIButton *)button{
    //最后一张图片为添加按钮对其进行特殊处理
    if (button.tag-140==_photoArr.count) {
        if (![UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
            [LZXHelper postMessageWithText:@"您的手机还不支持照相功能！" View:self.view];
            return;
        }
        if (_photoArr.count>=3) {
            [LZXHelper postMessageWithText:@"最多只能提交3张照片！" View:self.view];
            return;
        }
        NSString *cancelButtonTitle = NSLocalizedString(@"取消", nil);
        NSString *otherButtonTitle = NSLocalizedString(@"相册", nil);
        //        NSString *otherButtonTitle2 = NSLocalizedString(@"拍照", nil); 不支持拍照
        NSString *otherButtonTitle2 = NSLocalizedString(@"拍照", nil);
        
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
        
        // Create the actions.
        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelButtonTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction *action)
                                       {
                                           //cancel Button
                                       }];
        __weak EndHolidayViewController *myWeakSelf=self;
        //相册
        UIAlertAction *otherAction = [UIAlertAction actionWithTitle:otherButtonTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction *action)
                                      {
                                          
                                          //          NSLog(@"The \"Okay/Cancel\" alert's other action occured.");
                                          
                                          if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum])
                                          {
                                              //如果当前
                                              return;
                                          }
                                          UIImagePickerController *imagePickerController=[[UIImagePickerController alloc]init];
                                          imagePickerController.sourceType=UIImagePickerControllerSourceTypeSavedPhotosAlbum;
                                          imagePickerController.delegate = myWeakSelf;
                                          imagePickerController.allowsEditing=YES;
                                          [self presentViewController:imagePickerController animated:NO completion:nil];
                                      }];
        
        //        UIAlertAction *seeBigImgAction = [UIAlertAction actionWithTitle:otherButtonTitle2 style:UIAlertActionStyleDefault handler:^(UIAlertAction * action)
        //      {
        //          NSLog(@"here is bigImg Btn");
        ////            if (_photoURL==nil||_photoURL.length==0) {
        ////                return ;
        ////            }
        ////            PhotoImageViewController *photo=[[PhotoImageViewController alloc]init];
        ////            photo.photoImageURL=_photoURL;
        ////            [self.navigationController pushViewController:photo animated:YES];
        //      }];
        
        
        UIAlertAction *otherAction2 = [UIAlertAction actionWithTitle:otherButtonTitle2 style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
            //            NSLog(@"The \"Okay/Cancel\" alert's other action occured.");
            if (![UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear]) {
                [LZXHelper postMessageWithText:@"您的手机还不支持照相功能！" View:self.view];
            }
            UIImagePickerController *imagePickerController=[[UIImagePickerController alloc]init];
            imagePickerController.sourceType=UIImagePickerControllerSourceTypeCamera;
            imagePickerController.delegate=myWeakSelf;
            imagePickerController.allowsEditing=YES;
            [self presentViewController:imagePickerController animated:NO completion:nil];
        }];
        
        
        // Add the actions.
        [alertController addAction:otherAction2];
        //[alertController addAction:otherAction2];  不支持拍照
        [alertController addAction:cancelAction];
        [alertController addAction:otherAction];
        
        [self presentViewController:alertController animated:YES completion:nil];
        
        //        UIImagePickerController *imagePickerController=[[UIImagePickerController alloc]init];
        //        imagePickerController.sourceType=UIImagePickerControllerSourceTypeCamera;
        //        imagePickerController.delegate=self;
        //        imagePickerController.allowsEditing=YES;
        //        [self presentViewController:imagePickerController animated:NO completion:nil];
    }else{
        ImageDetailViewController *imageViewController=[ImageDetailViewController new];
        imageViewController.image=_photoArr[button.tag-140];
        [self.navigationController pushViewController:imageViewController animated:YES];
    }
    
}

#pragma mark -相册Delegate

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    //编辑时调用
    if (!info[@"UIImagePickerControllerEditedImage"])
    {
        return;
    }
    UIImage *image=info[@"UIImagePickerControllerEditedImage"];
    [_photoArr insertObject:image atIndex:0];
    //将拍的图片显示出来
//    for (int i=0;i<_photoButtonArr.count;i++) {
//        UIButton *photo=_photoButtonArr[i];
//        if (i<_photoArr.count) {
//            UIImage *image=_photoArr[i];
//            [photo setImage:image forState:UIControlStateNormal];
//            photo.hidden=NO;
//        }else{
//            photo.hidden=YES;
//        }
//        if (i==_photoArr.count) {
//            //[photo setImage:[UIImage imageNamed:@"AlbumAddBtn@2x"] forState:UIControlStateNormal];
//            photo.hidden=NO;
//        }
//    }
    //先移除再刷新
    for (UIButton *photo in _photoButtonArr) {
        [photo removeFromSuperview];
    }
    [_tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:2 inSection:1]] withRowAnimation:UITableViewRowAnimationNone];
    [picker dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark -获取当前时间请求

- (void)serverDateRequest{
    //[LZXHelper postLoadViewWithText:HUD_PLEASEWAIT View:self.view];
    
    NSString* soap = [NSString stringWithFormat:@"<sessionId>%@</sessionId>\n<content></content>",[LZXHelper getSessionID]];
    // __weak AddressBookViewController *mySelf=self;
    [HttpRequest SOAPData:[LZXHelper getServerURL] SoapMthod:getServiceTime soapBody:soap success:^(id responseObject) {
        //[LZXHelper hideLoadViewWithView:self.view];
        
        //解析数据
        BasicModel *model=[[BasicModel alloc]initWithResponse:responseObject];
        if ([model.code isEqualToString:@"200"]) {
            NSDictionary *dataDict=responseObject[@"retContent"];
            self.serviceTime=[dataDict[@"serviceTime"] copy];
            //格式化字符串
            NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
            [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
            NSDate *dateC = [dateFormatter dateFromString:self.endStr];
            [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
            NSDate *dateB = [dateFormatter dateFromString:self.serviceTime];
            NSComparisonResult resultB = [dateC compare:dateB];
            NSString *type=nil;
            if (resultB==NSOrderedSame) {
                type=@"正常销假";
            }else if (resultB==NSOrderedDescending){
                type=@"提前销假";
                self.isEdit=YES;
            }else{
                type=@"延迟销假";
            }
            self.holidayType.text=type;
        }else if([model.code isEqualToString:@"220"]){
            [LZXHelper postMessageWithText:model.msg View:self.view];
        }
    } failure:^(NSError *error) {
        //[LZXHelper hideLoadViewWithView:self.view];
    }];
}

#pragma mark -上传照片
- (void)uploadPhotoImage{
    //    if (!_image) {
    //        return;
    //    }
    //    [self.view addSubview:self.centerIndicator];
    //    [self.centerIndicator startAnimating];
    //    NSString *token=[[NSUserDefaults standardUserDefaults]objectForKey:@"Token"];
    //    NSIndexPath * selectedIndex = [_tableView indexPathForSelectedRow];
    //    MyInfoHeadViewCell * cell = [_tableView cellForRowAtIndexPath:selectedIndex];
    //    //NSString * sourcePath = [MyControl storeImagePath];
    //    PersonCenterViewController * pc = (PersonCenterViewController *)self.PersonVC;
    //
    
    NSMutableDictionary *picList=[NSMutableDictionary new];
    NSMutableArray *imageArr=[NSMutableArray new];
    
    for (int i=0; i<_photoArr.count; i++) {
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        
        [formatter setDateFormat:@"yyyyMMddHHmmssSSS"];
        //以时间为照片命名
        NSString *timestamp = [[formatter stringFromDate:[NSDate date]] stringByAppendingString:@".jpg"];
        
        UIImage *image=_photoArr[i];
        NSData *date = UIImageJPEGRepresentation(image, 0.5);
        NSString * imageStr = [date base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
        NSDictionary *dict=@{
                             @"picName":timestamp,
                             @"picBase":imageStr,
                             @"picType":@"xj",
                             };
        
        [imageArr addObject:dict];
    }
    
    [picList setObject:imageArr forKey:@"picList"];
    //   字典转json
    NSData* jsonData = [NSJSONSerialization dataWithJSONObject:picList options:NSJSONWritingPrettyPrinted error:nil];
    NSString* str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    //拼接soap字符串
    NSString* soap = [NSString stringWithFormat:@"<sessionId>%@</sessionId>\n<content>%@</content>",[LZXHelper getSessionID],str];
    
    [LZXHelper postLoadViewWithText:HUD_PLEASEWAIT View:self.view];
    
    [HttpRequest SOAPData:[LZXHelper getServerURL] SoapMthod:uploadPicInfo soapBody:soap success:^(id responseObject) {
        [LZXHelper hideLoadViewWithView:self.view];
        //解析数据并保存用户数据
        //NSLog(@"%@",responseObject[@"msg"]);
        _imageModel=[[UserHeadImageModel alloc]initWithResponse:responseObject];
        if ([_imageModel.code isEqualToString:@"200"]) {
            [self updateEliminateVacationInfoRequest];
        }else if([_imageModel.code isEqualToString:@"220"]){
            [LZXHelper postMessageWithText:_imageModel.msg View:self.view];
        }
        
    } failure:^(NSError *error) {
        [LZXHelper hideLoadViewWithView:self.view];
    }];
    
}

#pragma mark -更新提交销假信息
- (void)updateEliminateVacationInfoRequest{
    NSDateFormatter *formatter=[[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm"];
    NSString *timeStr=[formatter stringFromDate:[NSDate date]];
    //添加照片信息
    NSMutableArray *imageInfoArr=[NSMutableArray new];
    for (int i=0; i<_imageModel.dataArr.count; i++) {
        NSMutableDictionary *dict=[NSMutableDictionary new];
        UserHeadImageModel *model=_imageModel.dataArr[0];
        [dict setObject:model.picPath forKey:@"eliminatePicPath"];
        [dict setObject:model.picName forKey:@"eliminateProvePicName"];
        [imageInfoArr addObject:dict];
    }
    
    NSDictionary *dict=@{
                         @"eliminateType":self.holidayType.text?self.holidayType.text:@"",
                         @"vacateEndTime":self.endStr?self.endStr:@"",
                         @"vacateBeginTime":self.beginStr?self.beginStr:@"",
                         @"eliminateDescribe":self.reasonTextView.text,
                         @"infoId":self.infoId?self.infoId:@"",
                         @"serviceTime":self.serviceTime?self.serviceTime:timeStr,
                         @"vacateBillId":self.vacateBillId?self.vacateBillId:@"",
                         };
    NSMutableDictionary *newDict=[NSMutableDictionary dictionaryWithDictionary:dict];
    [newDict setObject:imageInfoArr forKey:@"eliminateProveList"];
    //   字典转json
    NSData* jsonData = [NSJSONSerialization dataWithJSONObject:newDict options:NSJSONWritingPrettyPrinted error:nil];
    NSString* str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    //拼接soap字符串
    NSString* soap = [NSString stringWithFormat:@"<sessionId>%@</sessionId>\n<content>%@</content>",[LZXHelper getSessionID],str];
    [LZXHelper postLoadViewWithText:HUD_PLEASEWAIT View:self.view];
    // __weak AddressBookViewController *mySelf=self;
    [HttpRequest SOAPData:[LZXHelper getServerURL] SoapMthod:updateEliminateVacationInfo soapBody:soap success:^(id responseObject) {
        [LZXHelper hideLoadViewWithView:self.view];
        
        //解析数据
        BasicModel *model=[[BasicModel alloc]initWithResponse:responseObject];
        if ([model.code isEqualToString:@"200"]) {
            NSDictionary *dict=responseObject[@"retContent"];
            NSString *isCanCommit=dict[@"isCanCommit"];
            NSString *message=dict[@"message"];
            if ([isCanCommit isEqualToString:@"0"]) {
                [LZXHelper postMessageWithText:message View:self.view];
                return;
            }else{
                [LZXHelper postAlertViewControllerWithTitle:@"确定要提交吗?" message:nil cancelButtonTitle:@"取消" otherButtonTitle:@"确定" cancelEvent:^{
                    [self postDeleteCancelBillRequest];
                } otherEvent:^{
                    [self postCommitDealInfoRequest];
                } viewController:self];
            }
        }else if([model.code isEqualToString:@"220"]){
            [LZXHelper postMessageWithText:model.msg View:[[UIApplication sharedApplication].delegate window]];
        }
    } failure:^(NSError *error) {
        [LZXHelper hideLoadViewWithView:self.view];
    }];
}


//这里不需要这个功能  重写
#pragma mark -已核销查看页面请假信息
- (void)getVacateInfoRequestWithVacateBillId:(NSString *)vacateBillId{
    
}

#pragma mark -获取倒计时间请求

- (void)getCountdownTimeInfoRequest{
    
    NSDictionary *dict=@{
                         @"businessCode":self.businessCode?self.businessCode:@"",
                         @"LeaveTypePK":self.keywordId?self.keywordId:@"",
                         @"type":@"3"
                         };
    
    //   字典转json
    NSData* jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];
    NSString* str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    //拼接soap字符串
    NSString* soap = [NSString stringWithFormat:@"<sessionId>%@</sessionId>\n<content>%@</content>",[LZXHelper getSessionID],str];
    // __weak AddressBookViewController *mySelf=self;
    [LZXHelper postLoadViewWithText:HUD_PLEASEWAIT View:self.view];
    [HttpRequest SOAPData:[LZXHelper getServerURL] SoapMthod:getCountdownTimeInfo soapBody:soap success:^(id responseObject) {
        [LZXHelper hideLoadViewWithView:self.view];
        
        //解析数据
        BasicModel *_model=[[BasicModel alloc]initWithResponse:responseObject];
        if ([_model.code isEqualToString:@"200"]) {
            NSDictionary *dict=responseObject[@"retContent"];
            NSInteger holidayCount=[dict[@"TimeLength"] integerValue];
            if (holidayCount%60>0) {
                //初始化时间
                _minute=holidayCount/60;
                //_minute=0;
                _second=holidayCount%60;
            }else{
                //初始化时间
                _minute=holidayCount/60-1;
                //_minute=0;
                _second=60;
            }
            _timer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(timerFunc) userInfo:nil repeats:YES];
        }else if([_model.code isEqualToString:@"220"]){
            [LZXHelper postMessageWithText:_model.msg View:self.view];
        }
    } failure:^(NSError *error) {
        [LZXHelper hideLoadViewWithView:self.view];
    }];
}

#pragma mark -确认提交信息
- (void)postCommitDealInfoRequest{
    NSDateFormatter *formatter=[[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm"];
    NSString *timeStr=[formatter stringFromDate:[NSDate date]];
    NSDictionary *dict=@{
                         @"dealSwitch":@"xj",
                         @"rules":@"",
                         @"infoId":self.infoId?self.infoId:@"",
                         @"serviceTime":self.serviceTime?self.serviceTime:timeStr,
                         @"vacateBillId":self.vacateBillId?self.vacateBillId:@"",
                         };
    //   字典转json
    NSData* jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];
    NSString* str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    //拼接soap字符串
    NSString* soap = [NSString stringWithFormat:@"<sessionId>%@</sessionId>\n<content>%@</content>",[LZXHelper getSessionID],str];
    [LZXHelper postLoadViewWithText:HUD_PLEASEWAIT View:self.view];
    // __weak AddressBookViewController *mySelf=self;
    [HttpRequest SOAPData:[LZXHelper getServerURL] SoapMthod:postCommitDealInfo soapBody:soap success:^(id responseObject) {
        [LZXHelper hideLoadViewWithView:self.view];
        
        //解析数据
        BasicModel *model=[[BasicModel alloc]initWithResponse:responseObject];
        if ([model.code isEqualToString:@"220"]) {
            [LZXHelper postMessageWithText:model.msg View:[[UIApplication sharedApplication].delegate window]];
            if (self.vacateBillId) {
                for (UIViewController *controller in self.navigationController.viewControllers) {
                    if ([controller isKindOfClass:[MyJobListViewController class]]) {
                        [self.navigationController popToViewController:controller animated:YES];
                    }
                }
            }else{
                [self.navigationController popViewControllerAnimated:YES];
            }
        }else if([model.code isEqualToString:@"200"]){
            [LZXHelper postMessageWithText:model.msg View:[[UIApplication sharedApplication].delegate window]];
        }
    } failure:^(NSError *error) {
        [LZXHelper hideLoadViewWithView:self.view];
    }];
}



#pragma mark -撤销销假信息
- (void)postDeleteCancelBillRequest{
    NSDictionary *dict=@{
                         @"vacateBillId":self.vacateBillId?self.vacateBillId:@"",
                         };
    //   字典转json
    NSData* jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];
    NSString* str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    //拼接soap字符串
    NSString* soap = [NSString stringWithFormat:@"<sessionId>%@</sessionId>\n<content>%@</content>",[LZXHelper getSessionID],str];
    [LZXHelper postLoadViewWithText:HUD_PLEASEWAIT View:self.view];
    // __weak AddressBookViewController *mySelf=self;
    [HttpRequest SOAPData:[LZXHelper getServerURL] SoapMthod:postDeleteCancelBill soapBody:soap success:^(id responseObject) {
        [LZXHelper hideLoadViewWithView:self.view];
        
        //解析数据
        BasicModel *model=[[BasicModel alloc]initWithResponse:responseObject];
        if ([model.code isEqualToString:@"220"]) {
            [LZXHelper postMessageWithText:model.msg View:[[UIApplication sharedApplication].delegate window]];
                [self.navigationController popViewControllerAnimated:YES];
        }else if([model.code isEqualToString:@"200"]){
            [LZXHelper postMessageWithText:model.msg View:[[UIApplication sharedApplication].delegate window]];
        }
    } failure:^(NSError *error) {
        [LZXHelper hideLoadViewWithView:self.view];
    }];
}

#pragma mark -获取请假天数

- (void)getVacateDaysOnlyRequest{
    if (!self.beginStr) {
        [LZXHelper postMessageWithText:@"请假开始时间不能为空!" View:self.view];
        return;
    }
    if (![self compareOneTime:self.beginStr withAnotherTime:self.endStr]) {
        [self setLabelBorderColorWithLabel:self.endTitleLabel color:[UIColor redColor]];
        [LZXHelper postMessageWithText:@"请假结束时间应该在请假开始时间之后!" View:self.view];
        return;
    }
    
    NSDictionary *dict=@{
                         @"businessCode":self.businessCode?self.businessCode:@"",
                         @"vacateBeginTime":self.beginStr?self.beginStr:@"",
                         @"vacateEndTime":self.endStr?self.endStr:@"",
                         @"LeaveTypePK":self.keywordId?self.keywordId:@"",
                         @"vacateBillId":self.vacateBillId?self.vacateBillId:@""
                         };
    
    //   字典转json
    NSData* jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];
    NSString* str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    //拼接soap字符串
    NSString* soap = [NSString stringWithFormat:@"<sessionId>%@</sessionId>\n<content>%@</content>",[LZXHelper getSessionID],str];
    //[LZXHelper postLoadViewWithText:HUD_PLEASEWAIT View:self.view];
    // __weak AddressBookViewController *mySelf=self;
    [HttpRequest SOAPData:[LZXHelper getServerURL] SoapMthod:getVacateDaysOnly soapBody:soap success:^(id responseObject) {
        //[LZXHelper hideLoadViewWithView:self.view];
        
        //解析数据
        BasicModel *model=[[BasicModel alloc]initWithResponse:responseObject];
        if ([model.code isEqualToString:@"200"]) {
            NSDictionary *dict=responseObject[@"retContent"];
            self.applyStr=dict[@"strflow"];
            self.holidayCount=dict[@"vacateDays"];
            //[_vacationTime sizeToFit];
            self.photoLabel.text=self.applyStr;
        }else if([model.code isEqualToString:@"220"]){
            [LZXHelper postMessageWithText:model.msg View:self.view];
        }
    } failure:^(NSError *error) {
        //[LZXHelper hideLoadViewWithView:self.view];
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
